package org.dromara.germbank.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.germbank.domain.BusApplicationPartner;
import org.dromara.germbank.domain.BusPartnerClinic;
import org.dromara.germbank.domain.bo.BusApplicationPartnerBo;
import org.dromara.germbank.domain.bo.BusPartnerClinicBo;
import org.dromara.germbank.domain.vo.BusApplicationPartnerVo;
import org.dromara.germbank.domain.vo.BusPartnerClinicVo;
import org.dromara.germbank.mapper.BusApplicationPartnerMapper;
import org.dromara.germbank.service.ApplicationPartnerService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 合作伙伴实施类
 *
 * @author congxing
 */

@Slf4j
@RequiredArgsConstructor
@Service
public class ApplicationPartnerServiceImpl implements ApplicationPartnerService {

    private final BusApplicationPartnerMapper busApplicationPartnerMapper;

    /**
     * 查询合作伙伴管理
     */
    @Override
    public TableDataInfo<BusApplicationPartnerVo> queryPageList(BusApplicationPartnerBo bo, PageQuery pageQuery) {

        Page<BusApplicationPartnerVo> page = busApplicationPartnerMapper.queryPageList(pageQuery.build(),this.buildQueryWrapper(bo));
        return TableDataInfo.build(page);
    }

    /**
     * 查询合作伙伴管理
     */
    @Override
    public boolean checkAdNameUnique(BusApplicationPartnerBo partner) {
        return false;
    }

    /**
     * 查询合作伙伴管理
     */
    @Override
    public int insertPartner(BusApplicationPartnerBo partner) {
        return 0;
    }

    /**
     * 查询合作伙伴管理
     */
    @Override
    public void updateDictData(BusApplicationPartnerBo partner) {

    }

    /**
     * 查询合作伙伴管理
     */
    @Override
    public void deletePartnerDataByIds(List<Long> partner) {

    }

    // 分页查询条件
    private Wrapper<BusApplicationPartner> buildQueryWrapper(BusApplicationPartnerBo bo) {
        return Wrappers.<BusApplicationPartner>lambdaQuery()
            .eq(BusApplicationPartner::getDel_flag, SystemConstants.NORMAL)

            // 法定名字
            .like(StringUtils.isNotBlank(bo.getFirstName()),
                BusApplicationPartner::getFirst_name, bo.getFirstName())

            // 法定姓氏
            .like(StringUtils.isNotBlank(bo.getLastName()),
                BusApplicationPartner::getLast_name, bo.getLastName())

            // 国家
            .eq(StringUtils.isNotBlank(bo.getCountry()),
                BusApplicationPartner::getCountry, bo.getCountry())

            // 城市
            .eq(StringUtils.isNotBlank(bo.getCity()),
                BusApplicationPartner::getCity, bo.getCity())

            // 街道地址
            .like(StringUtils.isNotBlank(bo.getStreet()),
                BusApplicationPartner::getStreet, bo.getStreet())

            // IVF诊所/机构名称
            .like(StringUtils.isNotBlank(bo.getClinicName()),
                BusApplicationPartner::getClinic_name, bo.getClinicName())

            .orderByAsc(BusApplicationPartner::getId);
    }
}
